<?php
session_start();
?>
<?php

require "lib/db.php";
require "lib/customer-function.php";
require "lib/address-function.php";

if(isset($_POST['btnAddCustomer'])){
	$customerName = $_POST['txtCustomerName'];
	$birthday = $_POST['txtBirthday'];
	$email = $_POST['txtEmail'];
	$phone = $_POST['txtPhone'];
	
	$houseNumber = $_POST['txtHouseNumber'];
	$street = $_POST['txtStreet'];
	$ward = $_POST['txtWard'];
	$district = $_POST['txtDistrict'];
	$city = $_POST['txtCity'];
	$addressID = addAddress($houseNumber, $street, $ward, $district, $city);
	
	$registerYear = $_POST['cbRegisterYear'];
	$registerMonth = $_POST['cbRegisterMonth'];
	
	addCustomer($customerName,$birthday,$email,$phone,$addressID,$registerYear,$registerMonth);
	header("location:list-customer.php");
}

if(isset($_POST['btnEditCustomer'])){
	$customerID = $_POST['hfCustomerID'];
	settype($customerID,"int");
	$customer = mysql_fetch_array(getCustomerByID($customerID));
	$addressID = $customer['AddressID'];
	
	$customerName = $_POST['txtCustomerName'];
	$birthday = $_POST['txtBirthday'];
	$email = $_POST['txtEmail'];
	$phone = $_POST['txtPhone'];
	
	$houseNumber = $_POST['txtHouseNumber'];
	$street = $_POST['txtStreet'];
	$ward = $_POST['txtWard'];
	$district = $_POST['txtDistrict'];
	$city = $_POST['txtCity'];
	editAddress($houseNumber,$street,$ward,$district,$city,$addressID);
	
	$registerYear = $_POST['cbRegisterYear'];
	$registerMonth = $_POST['cbRegisterMonth'];
	
	editCustomer($customerName,$birthday,$email,$phone,$registerYear,$registerMonth,$customerID);
	header("location:list-customer.php");
}
?>